package org.ptkparty.client.ui;

import java.util.List;

import org.ptkparty.client.model.PlaceProxy;

import com.google.gwt.editor.client.LeafValueEditor;
import com.google.gwt.user.client.ui.ListBox;

public class PlaceListBox extends ListBox implements LeafValueEditor<String> {

	@Override
	public void setValue(String value) {
		for (int i = 0; i < getItemCount(); i++) {
			if (getValue(i) == value) {
				setSelectedIndex(i);
				break;
			}
		}
	}

	@Override
	public String getValue() {
		if (getSelectedIndex() != -1) {
			return getValue(getSelectedIndex());
		} else {
			return null;
		}
	}

	public void setValues(List<PlaceProxy> placeProxies) {
		if (placeProxies != null) {
			for (PlaceProxy placeProxy : placeProxies) {
				addItem(placeProxy.getName(), placeProxy.getId());
			}
		}
	}

}
